﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Validity.Test.Constraints.StringConstraints
{
  [TestClass]
  public class HasMaximumLengthOfConstraint
    : ConstraintTestBase<ObjectStub>
  {
    public class Validator
      : ValidatorBase<ObjectStub>
    {
      public Validator()
      {
        DefineRulesFor(ctx => ctx.MyStringProperty1).HasMaximumLengthOf(10);
      }
    }

    public HasMaximumLengthOfConstraint() : base(new Validator(), 1) { }

    [TestMethod]
    public void TestConstraintVerified()
    {
      ValidateConstraintVerfied(CreateContext(null));
      ValidateConstraintVerfied(CreateContext(String.Empty));
      ValidateConstraintVerfied(CreateContext("          "));
      ValidateConstraintVerfied(CreateContext("1234567890"));
    }

    [TestMethod]
    public void TestConstraintViolated()
    {
      const String ruleViolation = "Must not exceed 10 chacaters in length. Length = 11";

      ValidateConstraintViolated(CreateContext("           "), ruleViolation);
      ValidateConstraintViolated(CreateContext("12345678901"), ruleViolation);
    }

    public ObjectStub CreateContext(String value)
    {
      var result = new ObjectStub();

      result.MyStringProperty1 = value;

      return result;
    }
  }
}
